package org.mics.core.page;

import org.springframework.data.domain.Page;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 分页信息
 * @author mics
 * @date 2020年6月17日
 * @version  1.0
 */
@Data
@Schema(description = "分页信息")
@EqualsAndHashCode(callSuper=false)
public class PageInfo {

    /**
     * 当前页数
     */
	@Schema(description = "当前页数")
    private int pageNo;

    /**
     * 每一页数据条数
     */
	@Schema(description = "每一页数据条数")
    private int pageSize;

    /**
     * 总页数
     */
	@Schema(description = "总页数")
    private int totalPage;

    /**
     * 总记录条数
     */
	@Schema(description = "总记录条数")
    private Long totalCount;

    
    public  synchronized static <T> PageInfo create(Page<T> page) {
    	PageInfo pageInfo = new PageInfo();
    	pageInfo.setPageNo(page.getNumber());
    	pageInfo.setPageSize(page.getSize());
    	pageInfo.setTotalCount(page.getTotalElements());
    	pageInfo.setTotalPage(page.getTotalPages());
		return pageInfo;
    }


}
